package com.hrzyit.whistle.cases.ui.adapter

import android.content.Context
import android.graphics.drawable.Drawable
import android.support.v4.content.ContextCompat
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.hrzyit.base.common.BaseApplication.Companion.context
import com.hrzyit.base.ui.adapter.BaseRecyclerViewAdapter
import com.hrzyit.base.utils.DateUtils
import com.hrzyit.base.utils.DimensionUtils
import com.hrzyit.whistle.cases.R
import com.hrzyit.whistle.cases.data.bean.CaseInfoProcessVo
import kotlinx.android.synthetic.main.item_case_time_line.view.*

/**
 *
 * @author YangWei
 * @date 2019/5/14
 */
class CaseTimeLineAdapter(context:Context):BaseRecyclerViewAdapter<CaseInfoProcessVo,CaseTimeLineAdapter.ViewHolder>(context){

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(context)
            .inflate(R.layout.item_case_time_line, parent, false)

        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        super.onBindViewHolder(holder, position)

        val item = dataList[position]
        holder.itemView.mCaseDateTv.text = DateUtils.convertTimeToString(item.addTime!!,DateUtils.FORMAT_LONG_NEW)
        holder.itemView.mOperatorInfoTv.text = String.format("%s(%s)",item.userName,item.deptName)
        holder.itemView.mProcessingInfoTv.text = item.operate
        val suggestion = if (item.suggestion.isNullOrEmpty()) {"无"} else {item.suggestion}
        holder.itemView.mSuggestionInfoTv.text = "处理意见:$suggestion"
        // 阶段名称：0 信息采集  1案件成立 2案件作废 3案件响应
        // 4案件退回 5案件批转 6案件受理 7案件结案 8数据导入 9中心批转
        // 10案件派遣 11案件吹哨  12申请结案 13结案退回 14案件处置
        var backgoundDrawable:Drawable
            when(item.processName) {
            7L -> {
                // 修改最后一个完成案件时间轴节点样式
                // 设置完成图标
                backgoundDrawable = ContextCompat.getDrawable(context,R.drawable.banlijindu_icon_message)!!
                // 设置字体颜色
                val color = ContextCompat.getColor(context,R.color.text_black)
                holder.itemView.mOperatorInfoTv.setTextColor(color)
                holder.itemView.mProcessingInfoTv.setTextColor(color)
                holder.itemView.mSuggestionInfoTv.setTextColor(color)
            }
            else -> {
                // 设置时间轴节点默认图标
                backgoundDrawable = ContextCompat.getDrawable(context,R.drawable.timeline_dot_normal)!!
                holder.itemView.mDotTv.width = DimensionUtils.dp2px(context,5f)
                holder.itemView.mDotTv.height = DimensionUtils.dp2px(context,5f)
            }
        }
        holder.itemView.mDotTv.background = backgoundDrawable

    }
    class ViewHolder(view:View):RecyclerView.ViewHolder(view)
}